<?php
/**
* Gives the links for each sizes of the image
*/
function smarty_function_sizelinks($params=array(), &$smarty)
{
	$params['id'] = isset($params['id'])?(int)$params['id']:'0';
	$params['code'] = isset($params['code'])?$params['code']:'*';
	$params['hardlink'] = (isset($params['hardlink']) && $params['hardlink']);
	$params['album'] = (isset($params['album']) && $params['album']);
	
	$urls = array();
	
	$db = new mysql();
	
	if($params['album'])
	{
		# section for album details
		
		/**
		* @todo Work on removing the image thumbnails created for obsolete, deleted or unapprovd images
		*/
		$album_sizes_sql="
SELECT
	`as`.album_id,
	`as`.store_location,
	s.size_id,
	s.size_name,
	s.size_code
FROM gallery_albums_sizes `as`
RIGHT OUTER JOIN gallery_sizes s
	ON `as`.size_id=s.size_id
	AND `as`.album_id={$params['id']}
WHERE
	s.is_active='Y'
	AND s.is_approved='Y'
ORDER BY
	#s.sink_weight,
	s.dimension_width,
	s.dimension_height
;";
		$sizes = $db->arrays($album_sizes_sql);
		$class_html='';
		foreach($sizes as $s => $size)
		{
			if($size['album_id'])
			{
				$class_html='';
				$urls[] = "{$size['size_name']}";
			}
			else
			{
				$class_html='not-working';
				$urls[] = "<a href='albumsizes-add.php?id={$params['id']}&amp;size={$size['size_id']}' class='{$class_html}' title='{$size['store_location']}'>{$size['size_name']}</a>";
			}
		}
	}
	else
	{
		
		/**
		* @todo Kick off this usage
		*/
		
		# Section for image details
		$sizes_sql="
SELECT
	size_id,
	size_name,
	size_code
FROM gallery_sizes
WHERE
	is_active='Y'
	AND is_approved='Y'
	AND size_code!=''
ORDER BY
	dimension_width,
	dimension_height
;";
		$sizes = $db->arrays($sizes_sql);
		if($params['hardlink']==true)
		{
			foreach($sizes as $s => $size)
			{
				$urls[] = "<a href='image/{$size['size_id']}/{$params['id']}.jpg'>{$size['size_name']}</a>";
			}
		}
		else
		{
			foreach($sizes as $s => $size)
			{
				$urls[] = "<a href='images-preview.php?id={$params['id']}&amp;code={$params['code']}&amp;size={$size['size_code']}'>{$size['size_name']}</a>";
			}
		}
	}
	
	return implode(' | ', $urls);
}
?>